function fv=cpar(r0,a,b,x,xlimit,v,dmy)
%**************************************************************
%** This is a supporting function for LS1.m                  **
%** Created by Min-Hua Huang, Jan 25, 2012                   **
%** r0: parameter estimates                                  **
%** a: lower bound                                           **
%** b: upper bound                                           **
%** x: independent variable matrix                           **
%** xlimit: maximim and minimum of the independent variables **
%** v: indicator variables                                   **
%** dmy: number of dummy variables                           **
%** output: constraints vectors                              **
%**************************************************************
m=size(x,2)-1; g=ones(2*m+4,1); m1=m+1-dmy; 
%maxty2=max((y2-mean(y2))/std(y2));
%minty2=min((y2-mean(y2))/std(y2));
%distmax=mean(y2)+maxty2*frac*std(y2);
%distmin=mean(y2)+minty2*frac*std(y2);
%maximum and minimum of dummnies
dmymax=max(r0(m1+1:m+1));
dmymin=min(r0(m1+1:m+1));
%maximum and minimum vectors of estimated y when xj is held at its min.
ynonj=ones(m+1,2)*-999;
ynonj(1,1)=(v(2:m1,1).*r0(2:m1))'*xlimit(2:m1,1)+dmymax;%+distmax;
ynonj(1,2)=(v(2:m1,2).*r0(2:m1))'*xlimit(2:m1,1)+dmymin;%+distmin;
for i=2:1:m1
    ynonj(i,1)=(v(1:m1,1).*r0(1:m1))'*xlimit(1:m1,1)-v(i,1)*r0(i)*xlimit(i,1)+dmymax;%+distmax;
    ynonj(i,2)=(v(1:m1,2).*r0(1:m1))'*xlimit(1:m1,1)-v(i,2)*r0(i)*xlimit(i,1)+dmymin;%+distmin;
end
ynonj(m1+1:m+1,1)=(v(1:m1,1).*r0(1:m1))'*xlimit(1:m1,1); %+distmax;
ynonj(m1+1:m+1,2)=(v(1:m1,2).*r0(1:m1))'*xlimit(1:m1,1); %+distmin;
%constraints vector
g(1)=r0(1)+ynonj(1,1)-b;
g(2)=-ynonj(1,2)-r0(1)+a;
g(3)=r0(1)-b;
g(4)=-r0(1)+a;
for i=1:1:m
    g(2*i+3)=r0(i+1)-(b-ynonj(i+1,1))/xlimit(i+1,1);
    g(2*i+4)=-r0(i+1)+(a-ynonj(i+1,2))/xlimit(i+1,1);
end
fv=g;     